﻿/**
*    @file:    widget.cpp
*    @brief:
*    @author:  sanshi522@163.com
*    @date:    2024-12-30  15:34
*/
#include "widget.h"
#include "ui_widget.h"

#include <QMenu>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // 设置应用程序的图标
    QApplication::setWindowIcon(QIcon(QString(QCoreApplication::applicationDirPath() + "/favicon.ico")));

    trayIcon = new QSystemTrayIcon(this);
    // 设置托盘图标的图标
    trayIcon->setIcon(QIcon(QString(QCoreApplication::applicationDirPath() + "/favicon.ico")));
    // 设置托盘图标的提示
    trayIcon->setToolTip("智能话音转写系统-服务端");
    // 创建菜单项
    QMenu *trayIconMenu = new QMenu(this);
    //    QAction *showAction = trayIconMenu->addAction("显示");
    QAction *quitAction = trayIconMenu->addAction("退出");

    //    connect(showAction, &QAction::triggered, this, &Widget::show);
    connect(quitAction, &QAction::triggered, qApp, &QApplication::quit);

    // 设置托盘图标的菜单
    trayIcon->setContextMenu(trayIconMenu);

    // 显示托盘图标
    if (trayIcon->isSystemTrayAvailable())
    {
        trayIcon->show();
    }
    else
    {
        qWarning() << "系统托盘不可用";
    }

    // 隐藏主窗口
    hide();

    serviceCenter = new ServiceCenter();
}

Widget::~Widget()
{
    delete serviceCenter;
    delete ui;
}
